package com.neo.subscribe.stamp.service;

import com.alibaba.fastjson.JSONObject;
import com.neo.subscribe.stamp.dto.Stamp;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.List;

public abstract class AbstractResponseProcess implements ResponseProcess{

    /**
     * 处理邮票分页数据
     * @param responseText
     * @return
     */
    protected List<Stamp> processStampPageData(String responseText) {
        if (StringUtils.isBlank(responseText)) {
            return Collections.EMPTY_LIST;
        }
        JSONObject responseJson = JSONObject.parseObject(responseText);
        if (MapUtils.isEmpty(responseJson)) {
            return Collections.EMPTY_LIST;
        }
        JSONObject data = responseJson.getJSONObject("data");
        if (MapUtils.isEmpty(data)) {
            return Collections.EMPTY_LIST;
        }

        JSONObject pageData = data.getJSONObject("pageData");
        if (MapUtils.isEmpty(pageData)) {
            return Collections.EMPTY_LIST;
        }
        return JSONObject.parseArray(pageData.getString("items"), Stamp.class);
    }
}
